<template>
  <el-dialog v-model="visible" :title="!dataForm.lrdId ? $t('add') : $t('update')" :close-on-click-modal="false" :close-on-press-escape="false">
    <el-form :model="dataForm" :rules="rules" ref="dataFormRef" @keyup.enter="dataFormSubmitHandle()" label-width="120px">
      <el-form-item label="任务id" prop="tskId">
        <el-input v-model="dataForm.tskId" placeholder="任务id"></el-input>
      </el-form-item>
      <el-form-item label="观众id" prop="psnId">
        <el-input v-model="dataForm.psnId" placeholder="观众id"></el-input>
      </el-form-item>
      <el-form-item label="联络类型" prop="tskType">
        <el-input v-model="dataForm.tskType" placeholder="联络类型"></el-input>
      </el-form-item>
      <el-form-item label="联络评价" prop="lrdGrade">
        <el-input v-model="dataForm.lrdGrade" placeholder="联络评价"></el-input>
      </el-form-item>
      <el-form-item label="联络结果" prop="lrdResult">
        <el-input v-model="dataForm.lrdResult" placeholder="联络结果"></el-input>
      </el-form-item>
      <el-form-item label="联络状态" prop="lrdLinkState">
        <el-input v-model="dataForm.lrdLinkState" placeholder="联络状态"></el-input>
      </el-form-item>
      <el-form-item label="联络原因" prop="lrdReason">
        <el-input v-model="dataForm.lrdReason" placeholder="联络原因"></el-input>
      </el-form-item>
      <el-form-item label="联络历史" prop="lrdHistory">
        <el-input v-model="dataForm.lrdHistory" placeholder="联络历史"></el-input>
      </el-form-item>
      <el-form-item label="计划联络时间" prop="lrdPlanTime">
        <el-input v-model="dataForm.lrdPlanTime" placeholder="计划联络时间"></el-input>
      </el-form-item>
      <el-form-item label="声音文件路径" prop="lrdRecordpath">
        <el-input v-model="dataForm.lrdRecordpath" placeholder="声音文件路径"></el-input>
      </el-form-item>
      <el-form-item label="联络目的" prop="lrdTarget">
        <el-input v-model="dataForm.lrdTarget" placeholder="联络目的"></el-input>
      </el-form-item>
      <el-form-item label="联络内容" prop="lrdContent">
        <el-input v-model="dataForm.lrdContent" placeholder="联络内容"></el-input>
      </el-form-item>
      <el-form-item label="回答的调查问题" prop="lrdAnswer">
        <el-input v-model="dataForm.lrdAnswer" placeholder="回答的调查问题"></el-input>
      </el-form-item>
      <el-form-item label="最后联络时间" prop="lrdLastLinkTime">
        <el-input v-model="dataForm.lrdLastLinkTime" placeholder="最后联络时间"></el-input>
      </el-form-item>
      <el-form-item label="最后联络人员id" prop="lrdLastLinkStfId">
        <el-input v-model="dataForm.lrdLastLinkStfId" placeholder="最后联络人员id"></el-input>
      </el-form-item>
      <el-form-item label="联络次数" prop="lrdTimes">
        <el-input v-model="dataForm.lrdTimes" placeholder="联络次数"></el-input>
      </el-form-item>
      <el-form-item label="状态" prop="lrdSysState">
        <el-input v-model="dataForm.lrdSysState" placeholder="状态"></el-input>
      </el-form-item>
      <el-form-item label="是否回复" prop="lrdIfBack">
        <el-input v-model="dataForm.lrdIfBack" placeholder="是否回复"></el-input>
      </el-form-item>
      <el-form-item label="备注" prop="lrdRemark">
        <el-input v-model="dataForm.lrdRemark" placeholder="备注"></el-input>
      </el-form-item>
      <el-form-item label="数据来源,如果是导入的则取临时表表名,否则是CRM的为空" prop="lrdSource">
        <el-input v-model="dataForm.lrdSource" placeholder="数据来源,如果是导入的则取临时表表名,否则是CRM的为空"></el-input>
      </el-form-item>
      <el-form-item label="regcard" prop="lrdRegcard">
        <el-input v-model="dataForm.lrdRegcard" placeholder="regcard"></el-input>
      </el-form-item>
      <el-form-item label="ifNew" prop="lrdIfNew">
        <el-input v-model="dataForm.lrdIfNew" placeholder="ifNew"></el-input>
      </el-form-item>
      <el-form-item label="ownerId" prop="lrdOwnerId">
        <el-input v-model="dataForm.lrdOwnerId" placeholder="ownerId"></el-input>
      </el-form-item>
      <el-form-item label="reply" prop="lrdReply">
        <el-input v-model="dataForm.lrdReply" placeholder="reply"></el-input>
      </el-form-item>
      <el-form-item label="nextTime" prop="lrdNextTime">
        <el-input v-model="dataForm.lrdNextTime" placeholder="nextTime"></el-input>
      </el-form-item>
      <el-form-item label="公司id" prop="comId">
        <el-input v-model="dataForm.comId" placeholder="公司id"></el-input>
      </el-form-item>
      <el-form-item label="展会id" prop="exhId">
        <el-input v-model="dataForm.exhId" placeholder="展会id"></el-input>
      </el-form-item>
      <el-form-item label="plkId" prop="plkId">
        <el-input v-model="dataForm.plkId" placeholder="plkId"></el-input>
      </el-form-item>
      <el-form-item label="actorcode" prop="actorcode">
        <el-input v-model="dataForm.actorcode" placeholder="actorcode"></el-input>
      </el-form-item>
      <el-form-item label="oldLrdId" prop="oldLrdId">
        <el-input v-model="dataForm.oldLrdId" placeholder="oldLrdId"></el-input>
      </el-form-item>
    </el-form>
    <template v-slot:footer>
      <el-button @click="visible = false">{{ $t("cancel") }}</el-button>
      <el-button type="primary" @click="dataFormSubmitHandle()">{{ $t("confirm") }}</el-button>
    </template>
  </el-dialog>
</template>

<script lang="ts" setup>
import { reactive, ref } from "vue";
import baseService from "@/service/baseService";
import { useI18n } from "vue-i18n";
import { ElMessage } from "element-plus";
const { t } = useI18n();
const emit = defineEmits(["refreshDataList"]);

const visible = ref(false);
const dataFormRef = ref();

const dataForm = reactive({
  lrdId: "",
  tskId: "",
  psnId: "",
  tskType: "",
  lrdGrade: "",
  lrdResult: "",
  lrdLinkState: "",
  lrdReason: "",
  lrdHistory: "",
  lrdPlanTime: "",
  lrdRecordpath: "",
  lrdTarget: "",
  lrdContent: "",
  lrdAnswer: "",
  lrdLastLinkTime: "",
  lrdCreator: "",
  lrdLastLinkStfId: "",
  lrdTimes: "",
  lrdSysState: "",
  lrdIfBack: "",
  lrdReplyTime: "",
  lrdRemark: "",
  lrdSource: "",
  lrdRegcard: "",
  lrdIfNew: "",
  lrdCreateTime: "",
  lrdOwnerId: "",
  lrdReply: "",
  lrdNextTime: "",
  comId: "",
  exhId: "",
  plkId: "",
  actorcode: "",
  oldLrdId: "",
  lrdUpdater: "",
  lrdUpdateTime: "",
});

const rules = ref({
});

const init = (lrdId?: number) => {
  visible.value = true;
  dataForm.lrdId = "";

  // 重置表单数据
  if (dataFormRef.value) {
    dataFormRef.value.resetFields();
  }

  if (lrdId) {
    getInfo(lrdId);
  }
};

// 获取信息
const getInfo = (lrdId: number) => {
  baseService.get("/crm/crmlinkrecord/" + lrdId).then((res) => {
    Object.assign(dataForm, res.data);
  });
};

// 表单提交
const dataFormSubmitHandle = () => {
  dataFormRef.value.validate((valid: boolean) => {
    if (!valid) {
      return false;
    }
    (!dataForm.lrdId ? baseService.post : baseService.put)("/crm/crmlinkrecord", dataForm).then((res) => {
      ElMessage.success({
        message: t("prompt.success"),
        duration: 500,
        onClose: () => {
          visible.value = false;
          emit("refreshDataList");
        }
      });
    });
  });
};

defineExpose({
  init
});
</script>